package binderipc
import android.content.UriMatcher
import android.os.Bundle
import androidx.core.app.BundleCompat
import binderipcremoteviews.TranscationRemoteViewsService
import bindipcbase.BaseContentProvider

class PassValueContentProvider : BaseContentProvider() {

    private val mUriMatcher = UriMatcher(UriMatcher.NO_MATCH)

    init {
        mUriMatcher.addURI(
            PassValueConstant.AUTHORITY,
            PassValueConstant.PATH,
            PassValueConstant.CODE
        )
    }

    override fun call(method: String, arg: String?, extras: Bundle?): Bundle? {
        if (PassValueConstant.ACTION_GET_SERVICE == method) {
            val bundle = Bundle()
            BundleCompat.putBinder(
                bundle,
                PassValueConstant.KEY_SERVER,
                PassValueService(context!!.cacheDir)
            )
            return bundle
        } else if (PassValueConstant.ACTION_PASS_REMOTE_VIEWS == method) {
            val bundle = Bundle()
            BundleCompat.putBinder(
                bundle,
                PassValueConstant.KEY_REMOTE_VIEWS,
                TranscationRemoteViewsService(context!!)
            )
            return bundle
        }
        return null
    }
}